#include <gfx/camera.h>
#include <scene/sector.h>

ceCamera::ceCamera()
  : _eye (ceVector3f (0, 0, 0))
  , _spot (ceVector3f (0, 0, -100))
  , _up (ceVector3f (0, 1, 0))
	, _sector (0)
{
}

ceCamera::~ceCamera ()
{
  CE_UNSET(_sector);
}

void ceCamera::SetEye(const ceVector3f &eye)
{
  _eye = eye;
}

const ceVector3f& ceCamera::GetEye() const
{
  return _eye;
}

void ceCamera::SetSpot(const ceVector3f &spot)
{
  _spot = spot;
}

const ceVector3f& ceCamera::GetSpot() const
{
  return _spot;
}

void ceCamera::SetUp(const ceVector3f &up)
{
  _up = up;
}

const ceVector3f& ceCamera::GetUp() const
{
  return _up;
}

void ceCamera::FinishTransformation()
{
  _matrix.SetLookAt(_eye, _spot, _up);
  _matrixInv = _matrix.Inverted();
}

const ceMatrix4f& ceCamera::GetMatrix() const
{
  return _matrix;
}

const ceMatrix4f& ceCamera::GetMatrixInv() const
{
  return _matrixInv;
}

void ceCamera::SetSector (ceSector* sector)
{
  CE_SET(_sector, sector);
}

ceSector* ceCamera::GetSector () 
{
	return _sector;
}

ceSector* ceCamera::GetSector () const
{
	return _sector;
}


ceVector3f ceCamera::GetPosInfront (float distance) const
{
	// get the normalised diretion from the eye in direction to the spot
	ceVector3f dir = _spot - _eye;
	dir.Normalize ();

	// the resulting point is distance * dir infront of the eye
	return _eye + (dir * distance);
}

